package com.oa.srms.apps.actions.student;

import java.awt.Font;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.security.MessageDigest;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.List;

import jxl.Sheet;
import jxl.Workbook;
import net.sf.json.JSONObject;

import org.apache.commons.codec.binary.Base64;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.entity.StandardEntityCollection;
import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
import org.jfree.chart.labels.StandardPieToolTipGenerator;
import org.jfree.chart.plot.PiePlot3D;
import org.jfree.chart.servlet.ServletUtilities;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.general.DefaultPieDataset;
import org.springframework.beans.factory.annotation.Autowired;

import com.oa.srms.apps.actions.BasicAction;
import com.oa.srms.apps.business.dormitory.IBedInfoService;
import com.oa.srms.apps.business.student.IAvatarInfoService;
import com.oa.srms.apps.business.student.IFamilyInfoService;
import com.oa.srms.apps.business.student.IMailInfoService;
import com.oa.srms.apps.business.student.IMajorInfoService;
import com.oa.srms.apps.business.student.IScoreInfoService;
import com.oa.srms.apps.business.student.IStudentDetailService;
import com.oa.srms.apps.business.student.IStudentInfoService;
import com.oa.srms.apps.constants.IDEDStates;
import com.oa.srms.apps.constants.IStudentStates;
import com.oa.srms.apps.entity.dormitory.BedInfoValue;
import com.oa.srms.apps.entity.student.MajorInfoValue;
import com.oa.srms.apps.entity.student.StudentInfoValue;

@SuppressWarnings("serial")
public class StudentInfoAction extends BasicAction {
	@Autowired
	private IStudentInfoService studentInfoService;
	@Autowired
	private IStudentDetailService studentDetailService;
	@Autowired
	private IMailInfoService mailInfoService;
	@Autowired
	private IAvatarInfoService avatarInfoService;
	@Autowired
	private IMajorInfoService majorInfoService;
	@Autowired
	private IBedInfoService bedInfoService;
	@Autowired
	private IFamilyInfoService familyInfoService;
	@Autowired
	private IScoreInfoService scoreInfoService;
	
	
	private List<MajorInfoValue> majorInfoList;
	private List<BedInfoValue> bedInfoList;
	private List<StudentInfoValue> stuList;
	private StudentInfoValue studentInfo;
	
	private String stuId;
	private String stuIds;
	private File stuPhoto;
	private String stuPhotoContentType;
	private String stuPhotoFileName;
	private String stuNo;
	private String stuName;
	private String idCard;
	private String gender;
	private String mail;
	private String politician;
	private String telphone;
	private String hometown;
	private String majorId;
	private String grade;
	private String classNo;
	private String cardId;
	private String fatherName;
	private String fatherTel;
	private String motherName;
	private String motherTel;
	private String address;
	private String examNo;
	private String chinese;
	private String math;
	private String english;
	private String comprehensive;
	private String states;
	private String avatarId;
	private String str;
	private String imageUrl;
	private String filename;
	private Integer classNum;
	
	private Integer bedId;
	private Integer mailId;
	private Integer detailId;
	private Integer familyId;
	private Integer scoreId;
	
	
	public String toAdd() throws Exception {
		majorInfoList = majorInfoService.queryMajorInfo(IDEDStates.ENABLE);
		return "toAddPage";
	}
	
	public String toUpdate() throws Exception {
		majorInfoList = majorInfoService.queryMajorInfo(IDEDStates.ENABLE);
		return "toUpdatePage";
	}
	
	public String toUpdateByStu() throws Exception {
		session.put("login_stuInfo", studentInfoService.queryById(8));///////////////////
		studentInfo = (StudentInfoValue)session.get("login_stuInfo");
		stuNo = studentInfo.getStuNo().toString();
		return "toUpdateByStuPage";
	}
	
	public String toEdit() throws Exception {
		majorInfoList = majorInfoService.queryMajorInfo(IDEDStates.ENABLE);
		return "toEditPage";
	}
	
	public String toRegistStu() throws Exception {
		return "toRegistStuPage";
	}
	
	public String toQueryDetailByStu() throws Exception {
		return "toQueryDetailByStuPage";
	}
	
	public String toQueryDetail() throws Exception {
		return "toQueryDetailPage";
	}
	
	public String toQuery() throws Exception {
		majorInfoList = majorInfoService.queryMajorInfo(IDEDStates.ENABLE);
		stuList = null;
		count = 0;
		totalpage = 1;
		return "toQueryPage";
	}
	
	public String toDistribute() throws Exception {
		majorInfoList = majorInfoService.queryMajorInfo(IDEDStates.ENABLE);
		stuList = null;
		count = 0;
		totalpage = 1;
		return "toDistributePage";
	}
	
	public String toModiyPwd() throws Exception {
		session.put("login_stuInfo", studentInfoService.queryById(8));///////////////////
		studentInfo = (StudentInfoValue)session.get("login_stuInfo");
		return "toModiyPwdPage";
	}
	
	public String addStudent() throws Exception {
		familyId = familyInfoService.addFamilyInfo(fatherName, fatherTel, motherName, motherTel, address);
		scoreId = scoreInfoService.addScoreInfo(examNo, Double.parseDouble(math), Double.parseDouble(chinese), Double.parseDouble(english), Double.parseDouble(comprehensive));
		detailId = studentDetailService.addStudentDetail(gender, idCard, hometown, politician, Integer.parseInt(majorId), Integer.parseInt(grade), telphone, familyId, cardId, scoreId);
		mailId = mailInfoService.addMailInfo(mail);
		FileInputStream fis = null;
		Integer avataInfoId = null;
		try{
			if(stuPhoto != null){
				fis = new FileInputStream(stuPhoto);
				int avatarSize = (int)stuPhoto.length();
				avataInfoId= avatarInfoService.addAvatarInfo(fis, avatarSize, stuPhotoContentType);
			}else{
				avataInfoId= avatarInfoService.addAvatarInfo(null, 0, stuPhotoContentType);
			}
		}finally{
			if(stuPhoto != null){
				fis.close();
			}
		}
		studentInfoService.addStudentInfo(stuNo, stuName, detailId, mailId, avataInfoId);
		return null;
	}
	
	public String batchAddStudent() throws Exception {
		Workbook book = null;
		str = "";
		try{
			
			book = Workbook.getWorkbook(new File(filename)); 
			// 获得第一个工作表对象 
			Sheet sheet = book.getSheet(0); 
			// 得到第row行第column的单元格 
			if(!"学号".equals(sheet.getCell(0,0).getContents()))str="0";
			if(!"姓名".equals(sheet.getCell(1,0).getContents()))str="0";
			if(!"性别".equals(sheet.getCell(2,0).getContents()))str="0";
			if(!"身份证号".equals(sheet.getCell(3,0).getContents()))str="0";
			if(!"邮箱".equals(sheet.getCell(4,0).getContents()))str="0";
			if(!"家乡".equals(sheet.getCell(5,0).getContents()))str="0";
			if(!"政治面貌".equals(sheet.getCell(6,0).getContents()))str="0";
			if(!"手机号码".equals(sheet.getCell(7,0).getContents()))str="0";
			if(!"专业".equals(sheet.getCell(8,0).getContents()))str="0";
			if(!"年级".equals(sheet.getCell(9,0).getContents()))str="0";
			if(!"银行卡号".equals(sheet.getCell(10,0).getContents()))str="0";
			if(!"父亲姓名".equals(sheet.getCell(11,0).getContents()))str="0";
			if(!"父亲联系电话".equals(sheet.getCell(12,0).getContents()))str="0";
			if(!"母亲姓名".equals(sheet.getCell(13,0).getContents()))str="0";
			if(!"母亲联系电话".equals(sheet.getCell(14,0).getContents()))str="0";
			if(!"家庭住址".equals(sheet.getCell(15,0).getContents()))str="0";
			if(!"考号".equals(sheet.getCell(16,0).getContents()))str="0";
			if(!"语文".equals(sheet.getCell(17,0).getContents()))str="0";
			if(!"数学".equals(sheet.getCell(18,0).getContents()))str="0";
			if(!"外语".equals(sheet.getCell(19,0).getContents()))str="0";
			if(!"综合".equals(sheet.getCell(20,0).getContents()))str="0";
			if(sheet.getRows()== 1) str ="-1";
			if(!"0".equals(str) && !"-1".equals(str)){
				String stuFail ="";
				for(int row = 1; row < sheet.getRows(); row++){
					boolean execute = true;
					String stuNo = sheet.getCell(0,row).getContents();
					if(!"".equals(stuNo) && studentInfoService.queryByStuNo(stuNo) != null){
						stuFail += row + ",";
						execute = false;
					}
					String stuName = sheet.getCell(1,row).getContents();
					String gender = sheet.getCell(2,row).getContents();
					if(!"男".equals(gender) && !"女".equals(gender)){
						if("0".equals(gender)){
							gender ="女";
						}else if("1".equals(gender)){
							gender ="男";
						}else{
							stuFail += row + ",";
							execute = false;
						}
					}
					String idCard = sheet.getCell(3,row).getContents();
					String mail = sheet.getCell(4,row).getContents();
					String hometown = sheet.getCell(5,row).getContents();
					String politician = sheet.getCell(6,row).getContents();
					String telphone = sheet.getCell(7,row).getContents();
					String majorId = sheet.getCell(8,row).getContents();
					if("".equals(majorId) || majorInfoService.queryByMajorId(Integer.parseInt(majorId)) == null){
						stuFail += row + ",";
						execute = false;
					}
					String grade = sheet.getCell(9,row).getContents();
					String cardId = sheet.getCell(10,row).getContents();
					String fatherName = sheet.getCell(11,row).getContents();
					String fatherTel = sheet.getCell(12,row).getContents();
					String motherName = sheet.getCell(13,row).getContents();
					String motherTel = sheet.getCell(14,row).getContents();
					String address = sheet.getCell(15,row).getContents();
					String examNo = sheet.getCell(16,row).getContents();
					String chinese = sheet.getCell(17,row).getContents();
					String math = sheet.getCell(18,row).getContents();
					String english = sheet.getCell(19,row).getContents();
					String comprehensive = sheet.getCell(20,row).getContents();
					if(execute){
						familyId = familyInfoService.addFamilyInfo(fatherName, fatherTel, motherName, motherTel, address);
						scoreId = scoreInfoService.addScoreInfo(examNo, Double.parseDouble(math), Double.parseDouble(chinese), Double.parseDouble(english), Double.parseDouble(comprehensive));
						detailId = studentDetailService.addStudentDetail(gender, idCard, hometown, politician, Integer.parseInt(majorId), Integer.parseInt(grade), telphone, familyId, cardId, scoreId);
						mailId = mailInfoService.addMailInfo(mail);
						int avataInfoId= avatarInfoService.addAvatarInfo(null, 0, null);
						studentInfoService.addStudentInfo(stuNo, stuName, detailId, mailId, avataInfoId);
					}
				}
				if("".equals(stuFail)){
					str = "1";
				}else{
					str = "部分新增成功。第"+stuFail.substring(0, stuFail.length()-1)+"行学生信息，因存在问题未新增成功！";
				}
			}
		} catch (Exception e) {
			//应做回滚操作，暂时忽略
			str = "-2";
		}finally {
			book.close(); 
		}
		response.setContentType("text/html; charset=UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		response.getWriter().write(str);
		return null;
	}
	
	public String delete() throws Exception{
		if(stuId != null)
			studentInfoService.deleteStudentInfo(Integer.parseInt(stuId));
		if(stuIds != null){
			String[] stuArr = stuIds.split(",");
			for(String stuItem : stuArr){
				studentInfoService.deleteStudentInfo(Integer.parseInt(stuItem));
			}
		}
		return "toQuery";
	}
	
	private int[][] classInfo;
	
	public String distributeByAverage() throws Exception {
		classInfo = new int[classNum][1];
		List<StudentInfoValue> totalList = studentInfoService.queryStudentInfo(null, Integer.parseInt(majorId), Integer.parseInt(grade));
		int classEveryNum = (totalList.size() % classNum == 0)?(totalList.size() / classNum):(totalList.size() / classNum + 1);
		if(totalList != null && totalList.size() != 0){
			List<StudentInfoValue> boyList = studentInfoService.queryStudentInfo("男", Integer.parseInt(majorId), Integer.parseInt(grade));
			List<StudentInfoValue> girlList = studentInfoService.queryStudentInfo("女", Integer.parseInt(majorId), Integer.parseInt(grade));
			if(boyList != null && boyList.size() != 0)
				this.toDistribute(classEveryNum, boyList);
			if(girlList != null && girlList.size() != 0)
				this.toDistribute(classEveryNum, girlList);
			str = "1";
		}else{
			str = "-1";
		}
		response.setContentType("text/html; charset=UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		response.getWriter().write(str);
		response.getWriter().close();
		return null;
	}
	
	protected void toDistribute(int classEveryNum, List<StudentInfoValue> list) throws Exception{
		
		int random = 0;
		int finalClassNum = 0;
		for(StudentInfoValue studentInfo : list){
			for(;;){
				random = (int) (Math.floor(Math.random() * 11) % classNum);
				if(classInfo[random][0] < classEveryNum){
					finalClassNum = random;
					break;
				}
			}
			classInfo[finalClassNum][0]++;
			studentDetailService.modifyStudentDetail(studentInfo.getStuDetail().getId(), finalClassNum + 1);
			studentInfoService.setStudentStates(studentInfo.getId(), IStudentStates.ALLOCATED);
		}
	}
	
	public String queryByStuNo() throws Exception{
		String str ="-1";
		studentInfo = studentInfoService.queryByStuNo(stuNo);
		if(studentInfo != null){
			JSONObject obj = JSONObject.fromObject(studentInfo);
			str = obj.toString();
		}
		response.setContentType("text/html; charset=utf-8");
		response.setHeader("Cache-Control", "no-cache");
		try {
			response.getWriter().print(str);
			response.getWriter().close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	public String queryStudent() throws Exception {
		majorInfoList = majorInfoService.queryMajorInfo(IDEDStates.ENABLE);
		Integer majorId = null;
		Integer grade = null;
		Integer classNo = null;
		Integer states = null;
		if("".equals(stuNo))
			stuNo = null;
		if("".equals(stuName))
			stuName = null;
		if("".equals(gender))
			gender = null;
		if(this.majorId != null && !"".equals(this.majorId)){
			majorId = Integer.parseInt(this.majorId);
		}
		if(this.grade != null && !"".equals(this.grade)){
			grade = Integer.parseInt(this.grade);
		}
		if(this.classNo != null && !"".equals(this.classNo)){
			classNo = Integer.parseInt(this.classNo);
		}
		if(this.states != null && !"".equals(this.states)){
			states = Integer.parseInt(this.states);
		}
		totalpage = studentInfoService.getTotalPageNumber(stuNo, stuName, gender,majorId, grade, classNo, states, rows);
		count = studentInfoService.getTotalNumber();
		stuList = studentInfoService.queryStudentInfo(stuNo, stuName, gender, majorId, grade, classNo, states, rows, currpage);
		return "toQueryPage";
	}
	
	public String queryStudentForDistribute() throws Exception {
		majorInfoList = majorInfoService.queryMajorInfo(IDEDStates.ENABLE);
		Integer majorId = null;
		Integer grade = null;
		Integer classNo = null;
		Integer states = null;
		if("".equals(stuNo))
			stuNo = null;
		if("".equals(stuName))
			stuName = null;
		if("".equals(gender))
			gender = null;
		if(this.majorId != null && !"".equals(this.majorId)){
			majorId = Integer.parseInt(this.majorId);
		}
		if(this.grade != null && !"".equals(this.grade)){
			grade = Integer.parseInt(this.grade);
		}
		if(this.classNo != null && !"".equals(this.classNo)){
			classNo = Integer.parseInt(this.classNo);
		}
		if(this.states != null && !"".equals(this.states)){
			states = Integer.parseInt(this.states);
		}
		if(!"".equals(this.states) && states == 1 ){
			totalpage = studentInfoService.getTotalPageNumberAboveStates(stuNo, stuName, gender,majorId, grade, classNo, states, rows);
			count = studentInfoService.getTotalNumber();
			stuList = studentInfoService.queryStudentInfoAboveStates(stuNo, stuName, gender, majorId, grade, classNo, states, rows, currpage);
		}else{
			totalpage = studentInfoService.getTotalPageNumber(stuNo, stuName, gender,majorId, grade, classNo, states, rows);
			count = studentInfoService.getTotalNumber();
			stuList = studentInfoService.queryStudentInfo(stuNo, stuName, gender, majorId, grade, classNo, states, rows, currpage);
		}
		return "toDistributePage";
	}
	
	public String queryBedInfo() throws Exception {
		if (gender != null && grade != null && classNo != null) {
			bedInfoList = bedInfoService.queryBedInfo(Integer.parseInt(grade), Integer.parseInt(classNo), gender, IDEDStates.ENABLE);
			response.setContentType("text/html; charset=UTF-8");
			response.setHeader("Cache-Control", "no-cache");
			if(bedInfoList.size() != 0 && bedInfoList != null){
				this.str = getBedInfoOptionsFrom(bedInfoList);
				response.getWriter().print(str);
			}else{
				this.str="<option value=\"-1\">-暂无床位-</option>";
				response.getWriter().print(str);
			}

		}

		return null;
	}
	
	protected String getBedInfoOptionsFrom(List<BedInfoValue> list) {
		StringBuilder sb = new StringBuilder();
		sb.append("<option value=\"\">-请选择-</option>");
		for (BedInfoValue piv : list) {
			String temp = "<option value=\"" + piv.getId()
					+ "\">" + piv.getBedInfoDetail() + "</option>";
			sb.append(temp);
		}
		return sb.toString();
	}
	
	
	public String modifyStudentAll() throws Exception {
		familyInfoService.modifyFamilyInfo(familyId, fatherName, fatherTel, motherName, motherTel, address);
		scoreInfoService.modifyScoreInfo(scoreId, examNo, Double.parseDouble(math), Double.parseDouble(chinese), Double.parseDouble(english), Double.parseDouble(comprehensive));
		Integer oldBedId = null;
		studentInfo = studentInfoService.queryById(Integer.parseInt(stuId));
		if(studentInfo.getStuDetail().getBedInfo() != null)
		oldBedId = studentInfo.getStuDetail().getBedInfo().getId();

		studentDetailService.modifyStudentDetail(detailId, gender, idCard, hometown, politician, Integer.parseInt(majorId), Integer.parseInt(grade), Integer.parseInt(classNo), telphone, bedId, cardId);
		mailInfoService.modifyMailInfo(mailId, mail);
		if(bedId != null && bedId != -1){
			bedInfoService.toDisable(bedId);
			if(oldBedId != null)
			bedInfoService.toEnable(oldBedId);
		}
		FileInputStream fis = null;
		try{
			if(stuPhoto != null){
				fis = new FileInputStream(stuPhoto);
				int avatarSize = (int)stuPhoto.length();
				avatarInfoService.modifyAvatarInfo(Integer.parseInt(avatarId), fis, avatarSize, stuPhotoContentType);
			}
		}finally{
			if(stuPhoto != null){
				fis.close();
			}
		}
		
		studentInfoService.modifyStudentInfo(Integer.parseInt(stuId), null, stuName, null);
		return "toEdit";
	}
	
	public String modifyStudentAllByStu() throws Exception {
		familyInfoService.modifyFamilyInfo(familyId, fatherName, fatherTel, motherName, motherTel, address);
		scoreInfoService.modifyScoreInfo(scoreId, examNo, Double.parseDouble(math), Double.parseDouble(chinese), Double.parseDouble(english), Double.parseDouble(comprehensive));
		Integer oldBedId = null;
		studentInfo = studentInfoService.queryById(Integer.parseInt(stuId));
		if(studentInfo.getStuDetail().getBedInfo() != null)
		oldBedId = studentInfo.getStuDetail().getBedInfo().getId();
		
		studentDetailService.modifyStudentDetail(detailId, gender, idCard, hometown, politician, Integer.parseInt(majorId), Integer.parseInt(grade), Integer.parseInt(classNo), telphone, bedId, cardId);
		mailInfoService.modifyMailInfo(mailId, mail);
		if(bedId != null && bedId != -1){
			bedInfoService.toDisable(bedId);
			if(oldBedId != null)
			bedInfoService.toEnable(oldBedId);
		}
		FileInputStream fis = null;
		try{
			if(stuPhoto != null){
				fis = new FileInputStream(stuPhoto);
				int avatarSize = (int)stuPhoto.length();
				avatarInfoService.modifyAvatarInfo(Integer.parseInt(avatarId), fis, avatarSize, stuPhotoContentType);
			}
		}finally{
			if(stuPhoto != null){
				fis.close();
			}
		}
		studentInfoService.modifyStudentInfo(Integer.parseInt(stuId), null, stuName, null);
		return "toQuery";
	}
	
	
	public String modifyStudentByStu() throws Exception {
		familyInfoService.modifyFamilyInfo(familyId, fatherName, fatherTel, motherName, motherTel, address);
		studentDetailService.modifyStudentDetail(detailId, politician, telphone);
		mailInfoService.modifyMailInfo(mailId, mail);
		FileInputStream fis = null;
		try{
			if(stuPhoto != null){
				fis = new FileInputStream(stuPhoto);
				int avatarSize = (int)stuPhoto.length();
				avatarInfoService.modifyAvatarInfo(Integer.parseInt(avatarId), fis, avatarSize, stuPhotoContentType);
			}
		}finally{
			if(stuPhoto != null){
				fis.close();
			}
		}
		studentInfoService.modifyStudentInfo(Integer.parseInt(stuId), null, stuName, null);
		return "toUpdateByStu";
	}
	
	public String registStudent() throws Exception {
		familyInfoService.modifyFamilyInfo(familyId, fatherName, fatherTel, motherName, motherTel, address);
		studentDetailService.modifyStudentDetail(detailId, Integer.parseInt(classNo), telphone, bedId);
		if(bedId != null && bedId != -1)
			bedInfoService.toDisable(bedId);
		FileInputStream fis = null;
		try{
			if(stuPhoto != null){
				fis = new FileInputStream(stuPhoto);
				int avatarSize = (int)stuPhoto.length();
				avatarInfoService.modifyAvatarInfo(Integer.parseInt(avatarId), fis, avatarSize, stuPhotoContentType);
			}
		}finally{
			if(stuPhoto != null){
				fis.close();
			}
		}
		studentInfoService.setStudentStates(Integer.parseInt(stuId), IStudentStates.ENROLLED);
		return "toRegistStu";
	}
	
	public String verifyMail() throws Exception{
		studentInfo = studentInfoService.queryByStuNo(stuNo);
		String verifyStr = studentInfo.getMailInfo().getMail()+"||"+studentInfo.getMailInfo().getVerifyCode();
		MessageDigest md = MessageDigest.getInstance("MD5");
		md.update(verifyStr.getBytes());
		String verifyMD5Str =Base64.encodeBase64URLSafeString(md.digest());
		if(verifyMD5Str.equals(str)){
			mailInfoService.modifyMailVerifyCode(studentInfo.getMailInfo().getMailId());
//			if(studentInfo.getStates() == IStudentStates.ALLOCATED )
//				studentInfoService.setStudentStates(studentInfo.getId(), IStudentStates.ACTIVE);
			return "toSuccess";
		}else{
			return "toFail";
		}
	}
	
	public String queryStudentInfoByImage() throws Exception {
		
		DefaultPieDataset dataset = new DefaultPieDataset();
		
		int createNum = studentInfoService.queryStudentInfo(IStudentStates.CREATE).size();
		int allocatedNum = studentInfoService.queryStudentInfo(IStudentStates.ALLOCATED).size();
		int activeNum = studentInfoService.queryStudentInfo(IStudentStates.ACTIVE).size();
		int checkNum = studentInfoService.queryStudentInfo(IStudentStates.CHECK).size();
		int enrolledNum = studentInfoService.queryStudentInfo(IStudentStates.ENROLLED).size();
		int unclaimedNum = studentInfoService.queryStudentInfo(IStudentStates.UNCLAIMED).size();
		int completeNum = studentInfoService.queryStudentInfo(IStudentStates.COMPLETE).size();
		
		dataset.setValue("建档", createNum);
		dataset.setValue("已分班", allocatedNum);
		dataset.setValue("已完成录取", activeNum);
		dataset.setValue("已财务审核", checkNum);
		dataset.setValue("已注册", enrolledNum);
		dataset.setValue("未领取完物品", unclaimedNum);
		dataset.setValue("完成入学流程", completeNum);
		
		JFreeChart chart1 = ChartFactory.createPieChart3D("学生状态统计分析饼状图", dataset, true, false, false);

		PiePlot3D plot1 = (PiePlot3D) chart1.getPlot();
		// 图片中显示百分比:默认方式
		plot1.setLabelGenerator(new StandardPieSectionLabelGenerator(
				StandardPieToolTipGenerator.DEFAULT_TOOLTIP_FORMAT));
		// 图片中显示百分比:自定义方式，{0} 表示选项， {1} 表示数值，
		//{2} 表示所占比例 ,小数点后两位
		plot1.setLabelGenerator(new StandardPieSectionLabelGenerator(
				"{0}={1}({2})", NumberFormat.getNumberInstance(),
				new DecimalFormat("0.00%")));
		// 图例显示百分比:自定义方式， {0} 表示选项， {1} 表示数值， {2} 表示所占比例
		plot1.setLegendLabelGenerator(new StandardPieSectionLabelGenerator(
						"{0}"));
		// 指定图片的透明度(0.0-1.0)
		plot1.setForegroundAlpha(1.0f);
		// 指定显示的饼图上圆形(true)还椭圆形(false)
		plot1.setCircular(true);
		// 设置图上分类标签label的字体，解决中文乱码
		plot1.setLabelFont(new Font("黑体", Font.PLAIN, 12));
		// 设置图上分类标签label的最大宽度，相对与plot的百分比
		plot1.setMaximumLabelWidth(0.2);
		// 设置3D饼图的Z轴高度（0.0～1.0）
		plot1.setDepthFactor(0.07);
		//设置起始角度，默认值为90，当为0时，起始值在3点钟方向
		plot1.setStartAngle(45);
 
		// 设置图标题的字体，解决中文乱码
		TextTitle textTitle = chart1.getTitle();
		textTitle.setFont(new Font("黑体", Font.PLAIN, 20));

		// 设置Legend部分字体，解决中文乱码
		chart1.getLegend().setItemFont(new Font("黑体", Font.BOLD, 15));
		
		ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
		String filename = ServletUtilities.saveChartAsPNG(chart1, 800, 450, info, httpSession);
		imageUrl = request.getContextPath()+"/servlet/DisplayChart?filename="+filename;
		
		return "toShowImage";
	}
	


	// Getter and Setter
	public File getStuPhoto() {
		return stuPhoto;
	}


	public void setStuPhoto(File stuPhoto) {
		this.stuPhoto = stuPhoto;
	}


	public String getStuNo() {
		return stuNo;
	}


	public void setStuNo(String stuNo) {
		this.stuNo = stuNo;
	}


	public String getStuName() {
		return stuName;
	}


	public void setStuName(String stuName) {
		this.stuName = stuName;
	}


	public String getIdCard() {
		return idCard;
	}


	public void setIdCard(String idCard) {
		this.idCard = idCard;
	}


	public String getGender() {
		return gender;
	}


	public void setGender(String gender) {
		this.gender = gender;
	}


	public String getMail() {
		return mail;
	}


	public void setMail(String mail) {
		this.mail = mail;
	}


	public String getPolitician() {
		return politician;
	}


	public void setPolitician(String politician) {
		this.politician = politician;
	}


	public String getTelphone() {
		return telphone;
	}


	public void setTelphone(String telphone) {
		this.telphone = telphone;
	}


	public String getMajorId() {
		return majorId;
	}


	public void setMajorId(String majorId) {
		this.majorId = majorId;
	}


	public String getGrade() {
		return grade;
	}


	public void setGrade(String grade) {
		this.grade = grade;
	}


	public String getClassNo() {
		return classNo;
	}


	public void setClassNo(String classNo) {
		this.classNo = classNo;
	}


	public String getCardId() {
		return cardId;
	}


	public void setCardId(String cardId) {
		this.cardId = cardId;
	}


	public String getFatherName() {
		return fatherName;
	}


	public void setFatherName(String fatherName) {
		this.fatherName = fatherName;
	}


	public String getFatherTel() {
		return fatherTel;
	}


	public void setFatherTel(String fatherTel) {
		this.fatherTel = fatherTel;
	}


	public String getMotherName() {
		return motherName;
	}


	public void setMotherName(String motherName) {
		this.motherName = motherName;
	}


	public String getMotherTel() {
		return motherTel;
	}


	public void setMotherTel(String motherTel) {
		this.motherTel = motherTel;
	}


	public String getAddress() {
		return address;
	}


	public void setAddress(String address) {
		this.address = address;
	}


	public String getExamNo() {
		return examNo;
	}


	public void setExamNo(String examNo) {
		this.examNo = examNo;
	}


	public String getChinese() {
		return chinese;
	}


	public void setChinese(String chinese) {
		this.chinese = chinese;
	}


	public String getMath() {
		return math;
	}


	public void setMath(String math) {
		this.math = math;
	}


	public String getEnglish() {
		return english;
	}


	public void setEnglish(String english) {
		this.english = english;
	}


	public String getComprehensive() {
		return comprehensive;
	}


	public void setComprehensive(String comprehensive) {
		this.comprehensive = comprehensive;
	}


	public List<MajorInfoValue> getMajorInfoList() {
		return majorInfoList;
	}


	public void setMajorInfoList(List<MajorInfoValue> majorInfoList) {
		this.majorInfoList = majorInfoList;
	}

	public String getHometown() {
		return hometown;
	}

	public void setHometown(String hometown) {
		this.hometown = hometown;
	}

	public String getStuPhotoContentType() {
		return stuPhotoContentType;
	}

	public void setStuPhotoContentType(String stuPhotoContentType) {
		this.stuPhotoContentType = stuPhotoContentType;
	}

	public String getStuPhotoFileName() {
		return stuPhotoFileName;
	}

	public void setStuPhotoFileName(String stuPhotoFileName) {
		this.stuPhotoFileName = stuPhotoFileName;
	}

	public StudentInfoValue getStudentInfo() {
		return studentInfo;
	}

	public void setStudentInfo(StudentInfoValue studentInfo) {
		this.studentInfo = studentInfo;
	}

	public List<BedInfoValue> getBedInfoList() {
		return bedInfoList;
	}

	public void setBedInfoList(List<BedInfoValue> bedInfoList) {
		this.bedInfoList = bedInfoList;
	}

	public List<StudentInfoValue> getStuList() {
		return stuList;
	}

	public void setStuList(List<StudentInfoValue> stuList) {
		this.stuList = stuList;
	}

	public String getStates() {
		return states;
	}

	public void setStates(String states) {
		this.states = states;
	}

	public String getStuId() {
		return stuId;
	}

	public void setStuId(String stuId) {
		this.stuId = stuId;
	}

	public String getAvatarId() {
		return avatarId;
	}

	public void setAvatarId(String avatarId) {
		this.avatarId = avatarId;
	}

	public String getStr() {
		return str;
	}

	public void setStr(String str) {
		this.str = str;
	}

	public Integer getBedId() {
		return bedId;
	}

	public void setBedId(Integer bedId) {
		this.bedId = bedId;
	}

	public Integer getMailId() {
		return mailId;
	}

	public void setMailId(Integer mailId) {
		this.mailId = mailId;
	}

	public Integer getDetailId() {
		return detailId;
	}

	public void setDetailId(Integer detailId) {
		this.detailId = detailId;
	}

	public Integer getFamilyId() {
		return familyId;
	}

	public void setFamilyId(Integer familyId) {
		this.familyId = familyId;
	}

	public Integer getScoreId() {
		return scoreId;
	}

	public void setScoreId(Integer scoreId) {
		this.scoreId = scoreId;
	}

	public String getStuIds() {
		return stuIds;
	}

	public void setStuIds(String stuIds) {
		this.stuIds = stuIds;
	}

	public String getImageUrl() {
		return imageUrl;
	}

	public void setImageUrl(String imageUrl) {
		this.imageUrl = imageUrl;
	}

	public String getFilename() {
		return filename;
	}

	public void setFilename(String filename) {
		this.filename = filename;
	}

	public Integer getClassNum() {
		return classNum;
	}

	public void setClassNum(Integer classNum) {
		this.classNum = classNum;
	}
	
	

}
